package com.ruoyi.warn.domain.vo;

import cn.hutool.core.convert.Convert;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ruoyi.common.annotation.OssUrl;
import com.ruoyi.common.utils.StringUtils;
import lombok.Data;
import org.apache.commons.compress.utils.Lists;

import java.util.List;

/**
 * @author zhangxiaohao
 * @comment 风险人员详情VO
 * @date 2023/4/6
 */
@Data
public class FxryDetailVo {

    /**
     * 主键
     */
    private String id;

    /**
     * 头像
     */
    private String avatar;

    @OssUrl
    public Object getAvatarInfo() {
        return avatar;
    }

    /**
     * 名称
     */
    private String name;

    /**
     * 身份证号
     */
    private String idno;

    /**
     * 风险等级
     */
    private String level;

    /**
     * 风险等级数据
     */
    @JsonIgnore
    private String fxdj;

    public String getLevel() {
        if (fxdj == null) {
            return null;
        } else {
            String[] highs = {"0", "1", "2", "3", "4"};
            String[] centers = {"5", "6", "7", "8", "9", "10", "11"};
            String[] lows = {"12", "13", "14"};
            String[] fxdjs = fxdj.split(",");
            List<String> levels = Lists.newArrayList();
            if (fxdjs.length > 0) {
                for (String fxdjStr : fxdjs) {
                    List<String> highList = Convert.toList(String.class, highs);
                    List<String> centerList = Convert.toList(String.class, centers);
                    List<String> lowList = Convert.toList(String.class, lows);
                    if (highList.contains(fxdjStr)) {
                        if (!levels.contains("0")) {
                            levels.add("0");
                        }
                    }
                    if (centerList.contains(fxdjStr)) {
                        if (!levels.contains("1")) {
                            levels.add("1");
                        }
                    }
                    if (lowList.contains(fxdjStr)) {
                        if (!levels.contains("2")) {
                            levels.add("2");
                        }
                    }
                }
            }
            return levels == null ? level : StringUtils.join(levels.toArray(), ",");
        }
    }
}
